package fizzpicks.tetrapulp.tetrapulp;

import java.util.Map;
import java.util.EnumMap;

public class Preset {
    Map<Options, Object> value;
    String name;

    /** Initializes objects as Enum / value pairs */
    Preset(String name, Object... values) {
        this.name = name;
        value = new EnumMap<Options,Object>(Options.class);
        Options opt = null;
        for (Object o : values) {
            if (o instanceof Options) {
                opt = (Options) o;
            } else {
                value.put(opt,o);
            }
        }
    }

    /** Applies a preset's Values map to an LJView playfield. */
    public void applyPreset(LJView v) {
        for (Map.Entry<Options,Object> o : value.entrySet()) {
            if (o.getKey() == Options.GIMMICK) { v.field.gimmick = (LJGM)o.getValue(); }
            else if(o.getKey() == Options.WIDTH) {
                int width = (Integer)o.getValue();
                v.field.leftWall = (Lockjaw.LJ_PF_WID - width) / 2;
                v.field.rightWall = v.field.leftWall + width;
            }
            else if(o.getKey() == Options.HEIGHT)       { v.field.ceiling = (Integer)o.getValue(); }
            else if(o.getKey() == Options.ENTER_ABOVE)  { v.field.enterAbove = (Boolean)o.getValue(); }
            else if(o.getKey() == Options.SPEED_CURVE)  { v.field.speedState.curve = (LJSPD)o.getValue(); }
            else if(o.getKey() == Options.ENTRY_DELAY)  { v.field.areStyle = (Integer)o.getValue(); }
            else if(o.getKey() == Options.PIECE_SET)    { v.field.pieceSet = (LJRAND2) o.getValue(); }
            else if(o.getKey() == Options.RANDOMIZER)   { v.field.randomizer = (LJRAND)o.getValue(); }
            else if(o.getKey() == Options.ROTATION_SYSTEM) { v.field.rotationSystem = (LJROT)o.getValue(); }
            else if(o.getKey() == Options.FLOOR_KICKS)  { v.field.maxUpwardKicks = (Integer)o.getValue(); }
            else if(o.getKey() == Options.HOLD_PIECE)   { v.field.holdStyle = (LJHOLD)o.getValue(); }
            else if(o.getKey() == Options.LOCKDOWN)     { v.field.lockReset = (LJLOCK)o.getValue(); }
            else if(o.getKey() == Options.LOCK_DELAY)   { v.field.setLockDelay = (byte)(int)(Integer)o.getValue(); }
            else if(o.getKey() == Options.BOTTOM_BLOCKS){ v.field.bottomBlocks = (byte)(int)(Integer)o.getValue(); }

            else if(o.getKey() == Options.LINE_DELAY)   { v.field.setLineDelay = (byte)(int)(Integer)o.getValue(); }
            else if(o.getKey() == Options.T_SPIN)       { v.field.tSpinAlgo = (LJTS)o.getValue(); }
            else if(o.getKey() == Options.CLEAR_GRAVITY){ v.field.clearGravity = (LJGRAV)o.getValue(); }
            else if(o.getKey() == Options.GLUING)       { v.field.gluing = (LJGLUING)o.getValue(); }
            else if(o.getKey() == Options.SCORING)      { v.field.scoreStyle = (LJSCORE)o.getValue(); }
            else if(o.getKey() == Options.DROP_SCORING) { v.field.dropScoreStyle = (LJDROP)o.getValue(); }
            else if(o.getKey() == Options.GARBAGE)      { v.field.garbageStyle = (LJGARBAGE)o.getValue(); }

            else if(o.getKey() == Options.SIDEWAYS_DELAY) { v.control.dasDelay = (Integer)o.getValue(); }
            else if(o.getKey() == Options.SIDEWAYS_SPEED) {
                v.control.dasSpeed = (Integer) o.getValue();
                if (v.control.dasDelay < v.control.dasSpeed) {
                    v.control.dasDelay = v.control.dasSpeed;
                }
            }
            else if(o.getKey() == Options.INITIAL_SIDEWAYS) { v.control.initialDAS = (Integer)o.getValue(); }
            else if(o.getKey() == Options.IRS)          { v.control.initialRotate = (Integer)o.getValue(); }
            else if(o.getKey() == Options.DIAGONAL_MOTION) { v.control.allowDiagonals = (Integer)o.getValue(); }
            else if(o.getKey() == Options.SOFT_DROP_SPEED) { v.control.softDropSpeed = (Integer)o.getValue(); }
            else if(o.getKey() == Options.SOFT_DROP)    { v.control.softDropLock = (Integer)o.getValue(); }
            else if(o.getKey() == Options.HARD_DROP)    { v.control.hardDropLock = (Integer)o.getValue(); }

            else if(o.getKey() == Options.SHADOW)       { v.hideShadow = (LJSHADOW)o.getValue(); }
            else if(o.getKey() == Options.HIDE_PF)      { v.hidePF = (Boolean)o.getValue(); }
            else if(o.getKey() == Options.NEXT_PIECES)  { v.nextPieces = (Integer)o.getValue(); }
            else if(o.getKey() == Options.SMOOTH_GRAVITY) { v.smoothGravity = (Boolean)o.getValue(); }
        }
    }
}
